<template>
    <div class="banxin tanxin box">
        <div class="box_l">
            <div class="box_l1">
                <h2>云音乐特色榜</h2>
                <ul>
                    <li v-for="item, index in tsInfo" :key="item.id"  @click="bdFn(item.id)">
                        <img :src="item.coverImgUrl" alt="">
                        <div class="nr">
                            <h3>{{ item.name }}</h3>
                            <span>{{ item.updateFrequency }}</span>
                        </div>
                    </li>
                </ul>
            </div>
            <div class="box_l2">
                <h2>全球媒体榜</h2>
                <ul>
                    <li v-for="item, index in mtInfo" :key="item.id" @click="bdFn(item.id)">
                        <img :src="item.coverImgUrl" alt="">
                        <div class="nr">
                            <h3>{{ item.name }}</h3>
                            <span>{{ item.updateFrequency }}</span>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
        <div>
    <div class="songList">
      <div class="tlt">
        <h3>歌曲列表</h3>
        <span class="sub">{{ bdInfo.trackCount }}首歌</span>
        <div class="more">
          播放：<span class="fc">{{ bdInfo.playCount }} </span>次
        </div>
      </div>
      <div class="song">
        <div class="header">
          <li class="w1"></li>
          <li class="w2">歌曲标题</li>
          <li class="w3">时长</li>
          <li class="w4">歌手</li>
          <li class="w5">专辑</li>
        </div>
        <div class="mainer">
          <ul v-for="(song, index) in Allgequ" :key="index">
            <li class="m1 ellipsis">
              <span>{{ index + 1 }}</span>
            </li>
            <li class="m2 ellipsis">
              <i class="play" @click="setMusic(song.id)"></i>
              <router-link :to="{ path: '/song', query: { id: `${song.id}` } }" :title="song.name">{{
                song.name
              }}</router-link>
              <i class="mv"></i>
            </li>
            <li class="m3 ellipsis">
              <span class="time">{{ min(song) }}:{{ sec(song) }}</span>
              <div class="show">
                <a text="添加到播放列表" class="a1" @click="addMusicList(song.id)"></a>
                <a text="收藏" class="a2"></a>
                <a text="分享" class="a3"></a>
                <a text="下载" class="a4"></a>
              </div>
            </li>
            <li class="m4 ellipsis">
              <router-link :to="{ path: '/artist/song', query: { id: song.ar[0].id } }">{{
                song.ar[0].name
              }}</router-link>
            </li>
            <li class="m5 ellipsis">
              <router-link :to="{ path: '/artist/song', query: { id: song.al.id } }">{{ song.al.name }}</router-link>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <audio :src="url" controls autoplay></audio>
  </div>
    </div>
</template>

<script>
import { Allbangdan,gedanxiang,Allgequ,reqSongUrl } from '@/request/api';
export default {
    data() {
        return {
            tsInfo: [],
            mtInfo: [],
            bdInfo:{},
            Allgequ:[],
            url:''
        }
    },
    methods:{
        bdFn(id){
            gedanxiang(id).then(res =>{
                // console.log(id);
                // console.log(res);
                this.bdInfo = res.data.playlist
            })
            Allgequ(id).then(res =>{
                console.log(res);
                this.Allgequ = res.data.songs
            })
        },
        setMusic(id) {
      // 获取音乐url
      reqSongUrl(id).then((res) => {
        // console.log(res.data.data[0].url);
        this.url = res.data.data[0].url;
      });
    },
    min(song) {
      if (parseInt(song.dt / 60000) < 10)
        return "0" + parseInt(song.dt / 60000);
      else return parseInt(song.dt / 60000);
    },
    sec(song) {
      let x = parseInt(song.dt / 60000);
      let y = parseInt(song.dt / 1000 - x * 60);
      if (y < 10) return "0" + y;
      else return y;
    },
    },
    created() {
        Allbangdan().then(res => {
            // console.log(res);
            let arr = res.data.list.map((item, index) => {
                return index <= 3 ? item : null
            })
            arr = arr.filter(item => {
                return item !== null
            })
            let arr2 = res.data.list.map((item, index) => {
                return index >= 4 ? item : null
            })
            arr2 = arr2.filter(item => {
                return item !== null
            })
            this.tsInfo = arr
            this.mtInfo = arr2
        })
        this.bdFn(19723756)
    }
}
</script>
 
<style lang = "less" scoped>
@import "../assets/base.less";

.box {
    .box_l {
        width: 30%;
        border-left: 1px solid #999;
        border-right: 1px solid #999;
        background-color: #f5f5f5;
        padding-top: 30px;

        .box_l1 {
            h2 {
                width: 100%;
                text-align: center;
                font-size: 14px;
                margin-bottom: 10px;
            }

            ul {
                li {
                    width: 240px;
                    padding: 10px 0;
                    margin-left: 20px;
                    display: flex;
                    cursor: pointer;
                    &:hover{
                        background-color: #ccc;
                    }
                    &.active {
                        background-color: #ccc;
                    }

                    img {
                        width: 40px;
                        height: 40px;
                        margin-right: 10px;
                    }

                    .nr {
                        h3 {
                            font-size: 12px;
                            color: #000;
                            margin-bottom: 10px;
                            display: -webkit-box; //对象作为弹性伸缩盒子模型显示
                            overflow: hidden; //溢出隐藏
                            -webkit-box-orient: vertical; //设置伸缩盒子对象的子元素的排列方式
                            -webkit-line-clamp: 1; //设置 块元素包含的文本行数
                        }

                        span {
                            font-size: 12px;
                            color: #999;
                        }
                    }
                }
            }
        }

        .box_l2 {
            h2 {
                width: 100%;
                text-align: center;
                font-size: 14px;
                margin-bottom: 10px;
            }

            ul {
                li {
                    width: 240px;
                    padding: 10px 0;
                    padding-left: 20px;
                    display: flex;
                    cursor: pointer;
                    &:hover{
                        background-color: #ccc;
                    }
                    &.active {
                        background-color: #ccc;
                    }

                    img {
                        width: 40px;
                        height: 40px;
                        margin-right: 10px;
                    }

                    .nr {
                        h3 {
                            padding-right: 20px;
                            font-size: 12px;
                            color: #000;
                            margin-bottom: 10px;
                            display: -webkit-box; //对象作为弹性伸缩盒子模型显示
                            overflow: hidden; //溢出隐藏
                            -webkit-box-orient: vertical; //设置伸缩盒子对象的子元素的排列方式
                            -webkit-line-clamp: 1; //设置 块元素包含的文本行数
                        }

                        span {
                            font-size: 12px;
                            color: #999;
                        }
                    }
                }
            }
        }
    }

    .box_r {
        width: 70%;
        border-right: 1px solid #999;
        background-color: #f5f5f5;
        .box_rt{
            display: flex;

            .imgbox{
                width: 150px;
                height: 150px;
                padding: 5px;
                border: 1px solid #999;
                img{
                    width: 100%;
                    height: 100%;
                }
            }
        }

    }
    .songList {
  // width: 670px;
  min-height: 400px;

  // margin: 0 auto;
  .tlt {
    width: 100%;
    height: 35px;
    border-bottom: 2px solid #c20c0c;

    h3 {
      font-family: "Microsoft Yahei", Arial, Helvetica, sans-serif;
      font-size: 20px;
      line-height: 28px;
      font-weight: normal;
      color: #333;
      float: left;
      margin-left: 26px;
    }

    .sub {
      margin: 9px 0 0 20px;
      float: left;
      color: #666;
      font-size: 12px;
      font-family: Arial, Helvetica, sans-serif;
      -webkit-text-size-adjust: none;
    }

    .more {
      margin-top: 5px;
      height: 16px;
      float: right;
      font-size: 12px;
      margin-right: 8px;

      .fc {
        color: #c20c0c;
        font-weight: bold;
      }
    }
  }

  .song {
    width: 100%;
    border: 1px solid #d9d9d9;

    .header {
      width: 100%;
      height: 39px;
      display: flex;
      font-size: 12px;
      color: #666;

      li {
        border-right: 1px solid #d9d9d9;
        background-image: linear-gradient(rgb(255, 255, 255),
            rgb(240, 240, 240));
        padding: 8px 10px;
        box-shadow: 0 1px 1px 1px rgba(0, 0, 0, 0.1);
        line-height: 26px;
      }

      .w1 {
        width: 61px;
      }

      .w2 {
        width: 275px;
      }

      .w3 {
        width: 91px;
      }

      .w4 {
        width: 82px;
      }

      .w5 {
        width: 125px;
      }
    }

    .mainer {
      width: 100%;
      display: block;
      font-size: 12px;

      a {
        color: #000;
        text-decoration: none;
      }

      ul:nth-of-type(even) {
        background: #e5e5e5;
      }

      ul:nth-of-type(odd) {
        background: #f6f6f6;
      }

      ul {
        height: 30px;
        width: 100%;
        display: flex;

        &:hover .time {
          display: none !important;
        }

        &:hover .show {
          display: block !important;
        }

        li {
          padding: 6px 10px;
        }

        .m1 {
          // width: 77px;
          // height: 100%;
          padding: 6px 10px;
          line-height: 18px;

          span {
            float: left;
            width: 25px;
            height: 18px;
            color: #999;
            text-align: center;
          }

          i {
            margin: 0 8px;
            float: left;
            width: 16px;
            height: 17px;
            background: url(../components/myMuc/images/icon.png) no-repeat -67px -283px;
          }
        }

        .m2 {
          width: 312px;
          line-height: 20px;

          img {
            float: left;
            margin-right: 10px;
            width: 50px;
            margin-top: 3px;
          }

          .play {
            float: left;
            display: block;
            width: 17px;
            height: 17px;
            margin-right: 8px;
            background: url("../components/myMuc/images/table.png") no-repeat -0px -103px;
            margin-top: 1px;

            &:hover {
              background-position: -0px -128px;
              cursor: pointer;
            }

            // background: url("../../images/table.png") no-repeat -20px -128px;
          }

          a {
            width: 260px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            float: left;
            margin-left: 10px;

            &:hover {
              color: #666;
              cursor: pointer;
              text-decoration: underline;
            }
          }
        }

        .m3 {
          width: 91px;

          .time {
            display: block;
          }

          .show {
            width: 79px;
            height: 18px;
            display: none;

            a {
              margin: 2px 0 0 4px;
              width: 18px;
              height: 16px;
              display: block;
              float: left;
              background: url("../components/myMuc/images/table.png") no-repeat;

              &:hover {
                cursor: pointer;
              }
            }

            .a1 {
              width: 13px;
              height: 13px;
              margin-top: 2px;
              margin-left: 0;
              background: url("../components/myMuc/images/icon.png") no-repeat;
              background-position: 0 -700px;

              &:hover {
                background-position: -22px -700px;
              }
            }

            .a2 {
              background-position: 0 -174px;

              &:hover {
                background-position: -20px -174px;
              }
            }

            .a3 {
              background-position: 0 -195px;

              &:hover {
                background-position: -20px -195px;
              }
            }

            .a4 {
              background-position: -81px -174px;

              &:hover {
                background-position: -104px -174px;
              }
            }
          }
        }

        .m4 {
          width: 82px;
          color: #333;

          & a:hover {
            color: #666;
            cursor: pointer;
            text-decoration: underline;
          }
        }

        .m5 {
          width: 132px;
          color: #333;

          & a:hover {
            color: #666;
            cursor: pointer;
            text-decoration: underline;
          }
        }
      }
    }
  }
}
}
</style>